package com.origin.grid.manager.controller.goods;

import com.origin.grid.framework.common.enums.ResultUtil;
import com.origin.grid.framework.common.vo.ResultMessage;
import com.origin.grid.framework.modules.goods.entity.vos.CategoryBrandVO;
import com.origin.grid.framework.modules.goods.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理端,分类品牌接口
 *
 * @author pikachu
 * @since 2020-02-27 15:18:56
 */
@RestController
@Schema(name = "管理端,分类品牌接口")
@RequestMapping("/manager/goods/categoryBrand")
public class CategoryBrandManagerController {

    /**
     * 规格品牌管理
     */
    @Autowired
    private CategoryBrandService categoryBrandService;

    @Schema(name = "查询某分类下绑定的品牌信息")
    @Parameter(name = "categoryId", description = "分类id", required = true, in = ParameterIn.PATH)
    @GetMapping(value = "/{categoryId}")
    public ResultMessage<List<CategoryBrandVO>> getCategoryBrand(@PathVariable String categoryId) {
        return ResultUtil.data(categoryBrandService.getCategoryBrandList(categoryId));
    }

    @Schema(name = "保存某分类下绑定的品牌信息")
    @PostMapping(value = "/{categoryId}")
    @Parameters({
            @Parameter(name = "categoryId", description = "分类id", required = true, in = ParameterIn.PATH),
            @Parameter(name = "categoryBrands", description = "品牌id数组", required = true, in = ParameterIn.QUERY, content = @Content(
                    array = @ArraySchema(
                            schema = @Schema(type = "string")
                    )
            ))
    })
    public ResultMessage<Object> saveCategoryBrand(@PathVariable String categoryId, @RequestParam List<String> categoryBrands) {
        categoryBrandService.saveCategoryBrandList(categoryId, categoryBrands);
        return ResultUtil.success();
    }

}
